<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
use think\Validate;
use \app\common\model\DayiRecord as DayiRecordModel;

/**
 * 答疑接口
 */
class Dayirecord extends Api
{
    /**
     * 答疑列表
     * @var array
     */
    protected $noNeedRight = '*';
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new DayiRecordModel();
    }

    /**
     * 答疑列表
     * @ApiTitle    (答疑列表)
     * @ApiMethod  (GET)
     * @ApiParams (name="student_id", type="int", required=true, description="学生ID")
     * @ApiParams (name="page", type="int", required=false, description="页码，默认为1")
     * @ApiParams (name="limit", type="int", required=false, description="每页数量，默认为10")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="200")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="查询成功")
     * @ApiReturnParams   (name="data", type="object", description="返回数据")
     * @ApiReturn   ({
          'code':'200',
          'msg':'查询成功',
          'time': "",
          'data': $data,
      })
     */
    public function dayirecordIndex()
    {
        $data = input('get.');
        $student_id = $data['student_id'];
        $page = isset($data['page']) ? intval($data['page']) : 1;
        $limit = isset($data['limit']) ? intval($data['limit']) : 10;
        if(!$student_id || !Validate::is($student_id, 'number')){
            $this->error('学生ID错误');
        }

        $dis = [
            'student_id' => $student_id,
        ];
        $row = $this->model->dataList($dis);

        $this->success('查询成功', $row);

    }

    /**
     * 答疑详情
     * @ApiTitle    (答疑详情)
     * @ApiMethod  (GET)
     * @ApiParams (name="id", type="int", required=true, description="答疑ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="200")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="查询成功")
     * @ApiReturnParams   (name="data", type="object", description="返回数据")
     * @ApiReturn   ({
          'code':'200',
          'msg':'查询成功',
          'time': "",
          'data': $data,
      })
     */
    public function dayirecordDetails(){
        $data = input('get.');
        $id = $data['id'];
        
        if(!$id || !Validate::is($id, 'number')){
            $this->error('答疑ID错误');
        }

        $dis = [
            'id' => $id,
        ];
        $row = $this->model->dataInfo($dis); 
        $this->success('查询成功', $row);
    }
    
}
